package com.campus.utils;

import com.campus.entity.SystemConfigs;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import javax.crypto.spec.PSource;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;

@Component
public class MailUtils {
    @Autowired
    private JavaMailSender emailSender;
//    @Resource(name = "ExecutorService")
//    private ThreadPoolExecutor threadPoolExecutor;

    @Async("ExecutorService")
    public void sendSimpleMessage(String to, String subject, String text) {
//        threadPoolExecutor.execute(() -> {
            SimpleMailMessage message = new SimpleMailMessage();
            message.setFrom("1486165831@qq.com");
            message.setTo(to);
            message.setSubject(subject);
            message.setText(text);
            long start = System.currentTimeMillis();
            emailSender.send(message);
            long end = System.currentTimeMillis();
            System.out.println("邮件发送成功！" + (end - start) );
//        });

    }
}
